package com.example.pluto.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * @Author: Mr.Yang
 * @CreateTime: 2022-08-28
 * @Description:
 */
@Getter
@AllArgsConstructor
public enum EnumException {

    /**
     * 验证码错误
     */
    FAIL_CAPTCHA_VALID(500, "验证码错误！"),


//    UN_AUTHORIZED(401, "您尚未获取该权限"),
//    IDEMPOTENT_END(403, "未携带幂等uuid"),

    /**
     * 您尚未登录或登录信息已失效, 请先登录！
     */
    LOGIN_TIME_OUT(501, "您尚未登录或登录信息已失效, 请先登录！"),
    /**
     * 请求验签失败
     */
    SING_FAIL(502, "请求验签失败"),


//    INTERFACE_ACCESS_EXCEEDS_FREQUENCY_LIMIT(500, "接口访问超出频率限制！"),

    ;

    private Integer code;
    private String message;

    public static EnumException match(Integer val, EnumException def) {
        return Stream.of(values()).parallel().filter((item) -> item.getCode().equals(val)).findAny().orElse(def);
    }

    public static EnumException get(Integer val) {
        return match(val, null);
    }
}
